// stats/stats_collector.rs
use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant};

#[derive(Default, Debug, Clone)]
pub struct Stats {
    pub total_requests: usize,
    pub success_requests: usize,
    pub failure_requests: usize,
    pub response_times: Vec<u64>,
}

impl Stats {
    pub fn new() -> Self {
        Stats {
            total_requests: 0,
            success_requests: 0,
            failure_requests: 0,
            response_times: Vec::new(),
        }
    }

    pub fn log_request(&mut self, success: bool, duration: u64) {
        self.total_requests += 1;
        if success {
            self.success_requests += 1;
        } else {
            self.failure_requests += 1;
        }
        self.response_times.push(duration);
    }

    pub fn average_response_time(&self) -> f64 {
        let total: u64 = self.response_times.iter().sum();
        total as f64 / self.response_times.len() as f64
    }
}
